package com.longge;

public class ReverseStr {
    public String reverseStr(String s, int k) {

        char[] chars = s.toCharArray();

        int start = 0, end = k - 1, count = 2 * k;
        while (start < chars.length) {
            reverse(chars, start, end);
            start = count;
            end = count + k - 1;
            count += 2 * k;
        }
        return new String(chars);
    }


    private char[] reverse(char[] chars, int start, int end) {

        if (end >= chars.length) end = chars.length - 1;
        while (start < end) {
            char temp = chars[start];
            chars[start] = chars[end];
            chars[end] = temp;
            start++;
            end--;
        }
        return chars;
    }
}
